﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Net;
using System.ComponentModel;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TwitterClient
{
    public class RateLimit
        : TwitterData
    {
        #region Public Properties

        public int RemainingHits { get; set; }

        public DateTime ResetTime { get; set; }

        public int HourlyLimit { get; set; }

        public int ResetTimeInSeconds { get; set; }

        #endregion

        #region Public Static Methods

        public static RateLimit Parse(string xml)
        {
            XElement element = XElement.Parse(xml);
            RateLimit status = new RateLimit();
            status.RemainingHits = int.Parse(element.Element("remaining-hits").Value);
            status.ResetTime = DateTime.ParseExact(element.Element("reset-time").Value, "yyyy-MM-dd'T'HH:mm:sszzz", System.Globalization.DateTimeFormatInfo.InvariantInfo);//
            status.HourlyLimit = int.Parse(element.Element("hourly-limit").Value);
            status.ResetTimeInSeconds = int.Parse(element.Element("reset-time-in-seconds").Value);
            return status;
        }

        #endregion

    }
}
